package org.arch_learn.rpc.nz_rpc.configuration;

import org.arch_learn.rpc.nz_rpc.endpoint.NettyRpcServer;
import org.arch_learn.rpc.nz_rpc.properties.NzRpcProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnBean(NzRpcProperties.class)
@AutoConfigureAfter(RPCAutoConfiguration.class)
public class RpcServerAutoConfiguration {
    @Autowired
    private ApplicationContext applicationContext;
    @Autowired
    private NzRpcProperties nzRpcProperties;

    //netty服务启动
    @Bean
    public NettyRpcServer nettyRpcServer() {
        NettyRpcServer nettyRpcServer = new NettyRpcServer();
        nettyRpcServer.startServer(nzRpcProperties.getNetty(), applicationContext);
        return nettyRpcServer;
    }

}
